package com.nangle.managehost.fragmet;

import android.app.Fragment;

import android.os.Bundle;

import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.GridView;


import com.nangle.managehost.BaseFargment;
import com.nangle.managehost.R;
import com.nangle.managehost.adapter.BedGridViewAdapter;
import com.nangle.managehost.adapter.MyGridViewAdapter;
import com.nangle.managehost.entity.Bed;
import com.nangle.managehost.entity.Patient;
import com.nangle.managehost.entity.Room;
import com.nangle.managehost.manager.BedManger;
import com.nangle.managehost.manager.PatientManager;
import com.nangle.managehost.manager.RoomManager;
import com.nangle.managehost.utils.Constants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：Administrator on 2016/8/31 13:53
 * 描述：
 */
public class SickBedFragment extends BaseFargment {

    private GridView gridView;

    private BedGridViewAdapter bedGridViewAdapter;
    private List<Map<String, Object>> list;
    private List<Room> mDatas = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.sickbed_layout, container, false);

        mDatas = getData();
        gridView = (GridView) view.findViewById(R.id.sickbed_grid);

        bedGridViewAdapter = new BedGridViewAdapter(getActivity(), mDatas);
        gridView.setAdapter(bedGridViewAdapter);

        return view;
    }




    private List<Room> getData(){

        List<Room> list1 = RoomManager.getInstance(mActivity).getRoomList();
        for(Room room : list1){
            List<Bed> list2 = BedManger.getInstance(mActivity).getBedList(String.valueOf(room.getRoomnumber()));
            List<Patient> patients = new ArrayList<>();
            for(Bed bed : list2){
                Patient patient = PatientManager.getInstance(mActivity).getPatient(String.valueOf(bed.getBedNumber()));
                patients.add(patient);
            }
            room.setPatients(patients);
        }

        return list1;
    }


}
